package com.scalar.chiptrack.operations.tapereel.actioncommands;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.scalar.ScalarException;
import com.scalar.chiptrack.users.User;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.actioncommands.ActionCommand;

import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: Sudhakar
 * Date: Apr 16, 2007
 * Time: 6:24:19 PM
 */
public class TapeReelRequestEditCommand extends ActionCommand
{
    private static final String ACTION_NAME = "/tapeReelRequest.do";
    
    public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response ) throws ScalarException
    {
        String actionType           = request.getParameter("actionType");
        ActionForward actionForward = mapping.findForward( "modify" );
        HttpSession mSession        = request.getSession();
        User user                   = ( User ) mSession.getAttribute ( SessionKeys.USER_KEY );
        HashMap errors              = new HashMap();
        HashMap info                = new HashMap();
        
        request.setAttribute( INFO_MESSAGES, info );
        request.setAttribute( ERROR_MESSAGES, errors );

        if ( user == null )
        {
            mSession.setAttribute ( SessionKeys.SOURCE_PAGE_KEY,  ACTION_NAME );
            return ( mapping.findForward ( "login" ) );
        }

        request.setAttribute( "actionType", actionType );
        request.setAttribute( INFO_MESSAGES, info );
        request.setAttribute( SessionKeys.ERROR_MESSAGES, errors );

        return actionForward;
    }
}
